package com.gg.user.gguser.dao;

import com.gg.user.gguser.dataobject.GgInformationDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GgInformationDaoMapper {

    //获取列表
    //@Select("select gg_i_id as ggIId, gg_i_name as ggIName, gg_i_province as ggIProvince, gg_i_city as ggICity, gg_i_detailed as ggIDetailed, gg_i_handle as ggIHandle, gg_i_contact as ggIContact, gg_i_level as ggILevel, gg_i_state as ggIState, gg_i_remarks as ggIRemarks from gg_information order by gg_i_time desc limit #{page},#{pageNumber}")


    @Select({"<script>",
            "select gg_i_telephone as ggITelephone,gg_i_areaid as ggIAreaid,gg_i_id as ggIId, gg_i_name as ggIName, gg_i_province as ggIProvince, gg_i_city as ggICity, gg_i_detailed as ggIDetailed, gg_i_handle as ggIHandle, gg_i_contact as ggIContact, gg_i_level as ggILevel, gg_i_state as ggIState, gg_i_remarks as ggIRemarks, gg_items_token as ggItemsToken from gg_information where gg_id=#{ggId}",
            "<if test='name!=null and name!=\"\"'>",
                "and gg_i_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
                "and gg_i_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
                "and gg_i_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
                "and gg_i_remarks like '%${remarks}%'",
            "</if>",
            "order by gg_i_time desc limit #{page},#{pageNumber}"
            ,"</script>"})
    List<GgInformationDataobject> getInformationSelectList(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber,@Param("ggId")String ggId,@Param("name")String name,@Param("type")Integer type,@Param("state")Integer state,@Param("remarks")String remarks);

    //获取一共多少个
    @Select({
            "<script>",
            "select count(*) from gg_information where gg_id=#{ggId}",
            "<if test='name!=null and name!=\"\"'>",
                "and gg_i_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
                "and gg_i_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
                "and gg_i_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
                "and gg_i_remarks  like '%${remarks}%'",
            "</if>"
            ,"</script>"
    })
    Integer getInformationSelectCount(@Param("ggId")String ggId,@Param("name")String name,@Param("type")Integer type,@Param("state")Integer state,@Param("remarks")String remarks);


    // 获取单个
    @Select("select gg_i_id as ggIId, gg_i_name as ggIName, gg_i_province as ggIProvince, gg_i_city as ggICity, gg_i_detailed as ggIDetailed, gg_i_handle as ggIHandle, gg_i_contact as ggIContact, gg_i_level as ggILevel, gg_i_state as ggIState,gg_i_time as ggITime,gg_i_gender as ggIGender, gg_i_position as ggIPosition, gg_i_telephone as ggITelephone, gg_i_fax as ggIFax, gg_i_mailbox as ggIMailbox, gg_i_qq as ggIQq, gg_i_wechat as ggIWechat, gg_i_remarks as ggIRemarks, gg_i_update as ggIUpdate, gg_i_areaid as ggIAreaid,gg_i_zipcode as ggIZipcode,gg_i_website as ggIWebsite,gg_i_source as ggISource  from gg_information where gg_items_token=#{itemsId}")
    GgInformationDataobject getInformationSelectItems( @Param("itemsId")String itemsId);

    // 修改备注
    @Update("update gg_information set gg_i_remarks=#{count} where gg_items_token=#{token} and gg_id=#{ggId}")
    Integer updateInformationRemarks(@Param("token")String token,@Param("count")String count,@Param("ggId")String ggId);

    // 查询---- 移入商机用
    @Select("select gg_i_id as ggIId, gg_i_name as ggIName, gg_i_province as ggIProvince, gg_i_city as ggICity, gg_i_detailed as ggIDetailed, gg_i_handle as ggIHandle, gg_i_contact as ggIContact, gg_i_level as ggILevel, gg_i_state as ggIState,gg_i_time as ggITime,gg_i_gender as ggIGender, gg_i_position as ggIPosition, gg_i_telephone as ggITelephone, gg_i_fax as ggIFax, gg_i_mailbox as ggIMailbox, gg_i_qq as ggIQq, gg_i_wechat as ggIWechat, gg_i_remarks as ggIRemarks,gg_id as ggId,gg_items_token as ggItemsToken, gg_i_areaid as ggIAreaid,gg_i_zipcode as ggIZipcode,gg_i_website as ggIWebsite,gg_i_source as ggISource from gg_information where gg_i_id=#{itemsId}")
    GgInformationDataobject getGgInformationDataobjectItems(@Param("itemsId")Integer itemsId);

    // 删除信息
    @Delete("delete from gg_information where gg_i_id=#{itemsId}")
    Integer delectGgInformationDataobjectItems(@Param("itemsId")Integer itemsId);

    // 从商机移入公海
    @Insert("insert into gg_information(gg_items_token,gg_i_name,gg_i_province,gg_i_city,gg_i_detailed,gg_i_handle,gg_i_contact,gg_i_state,gg_i_level,gg_i_gender,gg_i_position,gg_i_telephone,gg_i_fax,gg_i_mailbox,gg_i_qq,gg_i_wechat,gg_i_remarks,gg_id,gg_i_time,gg_i_areaid,gg_i_zipcode,gg_i_website,gg_i_source) values (#{ggItemsToken},#{ggIName},#{ggIProvince},#{ggICity},#{ggIDetailed},#{ggIHandle},#{ggIContact},#{ggIState},#{ggILevel},#{ggIGender},#{ggIPosition},#{ggITelephone},#{ggIFax},#{ggIMailbox},#{ggIQq},#{ggIWechat},#{ggIRemarks},#{ggId},#{ggITime},#{ggIAreaid},#{ggIZipcode},#{ggIWebsite},#{ggISource})")
    Integer addInformation(@Param("ggItemsToken")String ggItemsToken, @Param("ggIName")String ggIName, @Param("ggIProvince")String ggIProvince, @Param("ggICity")String ggICity, @Param("ggIDetailed")String ggIDetailed, @Param("ggIHandle")String ggIHandle, @Param("ggIContact")String ggIContact, @Param("ggIState")Integer ggIState, @Param("ggILevel")Integer ggILevel, @Param("ggIGender")String ggIGender, @Param("ggIPosition")String ggIPosition, @Param("ggITelephone")String ggITelephone, @Param("ggIFax")String ggIFax, @Param("ggIMailbox")String ggIMailbox, @Param("ggIQq")String ggIQq, @Param("ggIWechat")String ggIWechat, @Param("ggIRemarks")String ggIRemarks, @Param("ggId")String ggId, @Param("ggITime")String ggITime, @Param("ggIAreaid")String ggIAreaid,@Param("ggIZipcode")String ggIZipcode,@Param("ggIWebsite")String ggIWebsite,@Param("ggISource")String ggISource);

    // 直接插入
    @Insert("insert into gg_information(gg_items_token,gg_i_name,gg_i_province,gg_i_city,gg_i_areaid,gg_i_detailed,gg_i_handle,gg_i_contact,gg_i_state,gg_i_level,gg_i_gender,gg_i_position,gg_i_telephone,gg_i_fax,gg_i_mailbox,gg_i_qq,gg_i_wechat,gg_i_remarks,gg_id,gg_id_user,gg_i_zipcode,gg_i_website,gg_i_source) values (#{ggItemsToken},#{ggIName},#{ggIProvince},#{ggICity},#{ggIAreaid},#{ggIDetailed},#{ggIHandle},#{ggIContact},#{ggIState},#{ggILevel},#{ggIGender},#{ggIPosition},#{ggITelephone},#{ggIFax},#{ggIMailbox},#{ggIQq},#{ggIWechat},#{ggIRemarks},#{ggId},#{ggIdUser},#{ggIZipcode},#{ggIWebsite},#{ggISource})")
    Integer addInformationOpportunity(@Param("ggIName")String ggIName, @Param("ggIProvince")String ggIProvince, @Param("ggICity")String ggICity,@Param("ggIAreaid")String ggIAreaid, @Param("ggIDetailed")String ggIDetailed, @Param("ggIHandle")String ggIHandle, @Param("ggIContact")String ggIContact, @Param("ggIState")Integer ggIState, @Param("ggILevel")Integer ggILevel, @Param("ggIGender")String ggIGender, @Param("ggIPosition")String ggIPosition, @Param("ggITelephone")String ggITelephone, @Param("ggIFax")String ggIFax, @Param("ggIMailbox")String ggIMailbox, @Param("ggIQq")String ggIQq, @Param("ggIWechat")String ggIWechat, @Param("ggIRemarks")String ggIRemarks, @Param("ggId")String ggId, @Param("ggIdUser")String ggIdUser, @Param("ggItemsToken")String ggItemsToken,@Param("ggIZipcode")String ggIZipcode,@Param("ggIWebsite")String ggIWebsite,@Param("ggISource")String ggISource);

    // 修改商机信息
    @Update("update gg_information set gg_i_name=#{ggIName},gg_i_province=#{ggIProvince},gg_i_city=#{ggICity},gg_i_areaid=#{ggIAreaid},gg_i_detailed=#{ggIDetailed},gg_i_handle=#{ggIHandle},gg_i_contact=#{ggIContact},gg_i_level=#{ggILevel},gg_i_state=#{ggIState},gg_i_gender=#{ggIGender},gg_i_position=#{ggIPosition},gg_i_telephone=#{ggITelephone},gg_i_fax=#{ggIFax},gg_i_mailbox=#{ggIMailbox},gg_i_qq=#{ggIQq},gg_i_wechat=#{ggIWechat},gg_i_zipcode=#{ggIZipcode},gg_i_website=#{ggIWebsite},gg_i_source=#{ggISource} where gg_items_token=#{ggItemsToken} and gg_id_user=#{ggId}")
    Integer updateInformation(@Param("ggItemsToken")String ggItemsToken, @Param("ggIName")String ggIName, @Param("ggIProvince")String ggIProvince, @Param("ggICity")String ggICity,@Param("ggIAreaid")String ggIAreaid, @Param("ggIDetailed")String ggIDetailed, @Param("ggIHandle")String ggIHandle, @Param("ggIContact")String ggIContact, @Param("ggIState")Integer ggIState, @Param("ggILevel")Integer ggILevel, @Param("ggIGender")String ggIGender, @Param("ggIPosition")String ggIPosition, @Param("ggITelephone")String ggITelephone, @Param("ggIFax")String ggIFax, @Param("ggIMailbox")String ggIMailbox, @Param("ggIQq")String ggIQq, @Param("ggIWechat")String ggIWechat, @Param("ggId")String ggId,@Param("ggIZipcode")String ggIZipcode,@Param("ggIWebsite")String ggIWebsite,@Param("ggISource")String ggISource);

    // 查询详情
    @Select("select gg_items_token as ggItemsToken,gg_i_name as ggIName,gg_i_province as ggIProvince,gg_i_city as ggICity,gg_i_detailed as ggIDetailed,gg_i_handle as ggIHandle,gg_i_contact as ggIContact,gg_i_state as ggIState,gg_i_level as ggILevel,gg_i_gender as ggIGender,gg_i_position as ggIPosition,gg_i_telephone as ggITelephone,gg_i_fax as ggIFax,gg_i_mailbox as ggIMailbox,gg_i_qq as ggIQq,gg_i_wechat as ggIWechat,gg_i_remarks as ggIRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_i_time as ggITime, gg_i_areaid as ggIAreaid,gg_i_zipcode as ggIZipcode,gg_i_website as ggIWebsite,gg_i_source as ggISource from gg_information where gg_i_id=#{itemsId}")
    GgInformationDataobject getBusinessOpportunity(@Param("itemsId")Integer itemsId);
}
